GPX: Avoid a realloc/copy when reading large data segments that come in multiple...
authorrobertl <robertl>
Sat, 14 Jun 2008 14:44:11 +0000 (14:44 +0000)
committerrobertl <robertl>
Sat, 14 Jun 2008 14:44:11 +0000 (14:44 +0000)
p

gpx.c

diff --git a/gpx.c b/gpx.c
index 20121117bbd7a8ab04bd6d7c59244e5fd2c2cea6..5b13010c3b92d20979432c7bc9e37add519bf5f6 100644 (file)
--- a/gpx.c
+++ b/gpx.c
@@ -1,7 +1,7 @@
 /*
     Access GPX data files.
 
-    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Robert Lipe, robertlipe@usa.net
+    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Robert Lipe, robertlipe@usa.net
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -634,10 +634,9 @@ gpx_start(void *data, const XML_Char *xml_el, const XML_Char **xml_attr)
 
        
        /*
-        * FIXME: Find out why a cdatastr[0] doesn't adequately reset the       
-        * cdata handler.
+        * Reset end-of-string without actually emptying/reallocing cdatastr.
         */
-       memset(cdatastr.mem, 0, cdatastr.size);
+       *(char *) cdatastr.mem = 0;
 
        switch (get_tag(current_tag.mem, &passthrough)) {
        case tt_gpx:
@@ -1162,7 +1161,7 @@ gpx_cdata(void *dta, const XML_Char *xml_el, int len)
        memcpy(estr, s, len);
        estr[len]  = 0;
 
-       if (!cur_tag) 
+       if (!cur_tag)
                return;
 
                if ( cur_tag->child ) {
@@ -1178,11 +1177,7 @@ gpx_cdata(void *dta, const XML_Char *xml_el, int len)
                        cdatalen = &(cur_tag->cdatalen);
                }
                estr = *cdata;
-               *cdata = xcalloc( *cdatalen + len + 1, 1);
-               if ( estr ) {
-                       memcpy( *cdata, estr, *cdatalen);
-                       xfree( estr );
-               }
+               *cdata = xrealloc(*cdata, *cdatalen + len + 1);
                estr = *cdata + *cdatalen;
                memcpy( estr, s, len );
                *(estr+len) = '\0';